package com.aletto.general_store.ui.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.aletto.general_store.R;
import com.aletto.general_store.ui.activities.orders.AppealOrderActivity;
import com.aletto.general_store.utils.DataCleanManager;
import com.aletto.general_store.utils.Login;
import com.aletto.general_store.utils.ToastUtils;
import com.aletto.general_store.utils.XHelper;

public class SettingsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        XHelper.initTitle(this, R.string.settings);

        TextView tvCache = findViewById(R.id.tv_cache);
        try {
            tvCache.setText(DataCleanManager.getTotalCacheSize(this));

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        // 订单申诉
        View layout_order_appeal = findViewById(R.id.layout_order_appeal);
        layout_order_appeal.setVisibility(View.VISIBLE);
        layout_order_appeal.setOnClickListener(v ->
                startActivity(new Intent(this, AppealOrderActivity.class)));

        // 清理垃圾
        findViewById(R.id.clean_layout).setOnClickListener(v -> {
            tvCache.setText("0.0KB");
            DataCleanManager.clearAllCache(v.getContext());
            ToastUtils.makeText(R.string.clear_cache_success);
        });

        findViewById(R.id.layout_block_node).setOnClickListener(v -> // 节点列表
                startActivity(new Intent(this, ChainNodesActivity.class)));

        findViewById(R.id.layout_feedback).setOnClickListener(v -> // 评价&反馈
                startActivity(new Intent(this, FeedbackActivity.class)));

        findViewById(R.id.layout_about_us).setOnClickListener(v -> // 关于我们
                startActivity(new Intent(this, AboutUsActivity.class)));

        findViewById(R.id.layout_address_book).setOnClickListener(new Login(v -> // 收货地址
                startActivity(AddressManageActivity.newIntent(v.getContext()))));

        findViewById(R.id.layout_language).setOnClickListener(v -> // 语言
                startActivity(new Intent(this, LanguageActivity.class)));
    }

}
